-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Improve CustomNSError.errorDomain calculation #5132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve CustomNSError.errorDomain calculation #5132
Conversation
@swift-ci please test |
This patch will help for non-Darwin platforms - the Foundation.framework (Darwin) version is here. |
@swift-ci test |
Sources/Foundation/NSError.swift
Outdated
@@ -300,7 +300,7 @@ public protocol CustomNSError : Error { | |||
public extension CustomNSError { | |||
/// Default domain of the error. | |||
static var errorDomain: String { | |||
return String(reflecting: self) | |||
return _typeName(type(of: self), qualified: true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jmschonfeld you've used this function for Predicate
- does it seem right here too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah _typeName(self)
is a fine way to get the fully qualified name here - just to confirm, @Azoy is it always the case that String(reflecting: someType)
will always just return the fully qualified type name here or do you know of any types that might somehow produce a different value via String(reflecting:)
here (just to make sure we don't accidentally change behavior)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah it should always return a qualified name.
Hi Tony! Thanks for quick review, really appreciate it! Thanks for pointing it out! I'll open same MR shortly. |
Here is the same MR for Darwin platforms: |
851118b
to
fe2faba
Compare
@swift-ci test |
@swift-ci please test Windows platform |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One more thing - can we verify we have a unit test for this behavior?
Sure, here it is TestNSError.swift It would be great if you could review similar Pull-Requests: |
It looks like the linux test failed in a SwiftPM test with
It's not immediately apparent how that could be related to this change. @ChrisBenua any thoughts, or should we try a re-run to see if it was an intermittent issue |
Windows passed and this isn't platform specific so I'll just rerun Linux and see what happens 🙂 |
@swift-ci please test Linux platform |
It's unclear to me how my changes can possibly affect SPM. Linux tests passed after re-run, so most likely it was intermittent issue |
@jmschonfeld, I was wondering if you could please ask someone from your colleagues to take a look at similar PR: swiftlang/swift#77369? It would be greatly appreciated. Thank you in advance for your consideration. |
Optimized
CustomNSError.errorDomain
calculation.String(reflecting:)
forAny.Type
objects eventually calls_type(:qualified:)
. ButString(reflecting:)
call has overhead because ofas?
checks.All details are listed in issue.